package middleware

import (
	"mldong/api/base"

	"github.com/gogf/gf/v2/net/ghttp"
)

// ErrorHandlerMiddleware 错误处理中间件
func init() {
	RegisterMiddleware(ErrorHandlerMiddleware, 0)
}
func ErrorHandlerMiddleware(r *ghttp.Request) {
	r.Middleware.Next()

	var (
		msg string
		err = r.GetError()
	)
	if err != nil {
		msg = err.Error()
		r.Response.WriteJson(base.FailWithDefaultCode(msg))
	}
}
